package com.Maykk.Demo03;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Random;

/**
 * @ClassName: Demo02
 * @Description: TODO Collection 生成双色球号码
 * 双色球规则：6个1-33的红球，1个1-16的蓝球
 * @Author: MaykkStar@163.com
 */
public class Demo02 {
    public static void main(String[] args) {
        Random ran = new Random();
        int[] redBalls = new int[6];

        for (int i = 0, j; i < 6; i++) {
            int rb = ran.nextInt(33) + 1;
            for (j = 0; j < i; j++) {
                if (redBalls[j] == rb) {
                    i--;
                    break;
                }
            }
            redBalls[j] = rb;
        }
        // 冒泡排序
        for (int i = 0; i < redBalls.length - 1; i++) {
            for (int j = 0; j < redBalls.length - 1 - i; j++) {
                if (redBalls[j] > redBalls[j + 1]) {
                    redBalls[j] ^= redBalls[j + 1];
                    redBalls[j + 1] ^= redBalls[j];
                    redBalls[j] ^= redBalls[j + 1];
                }
            }
        }
        int blueBall = ran.nextInt(16) + 1;
        System.out.println("红球：" + Arrays.toString(redBalls) + " 蓝球：[" + blueBall + "]");

        /**
         * 用集合实现
         */
        // Random ran = new Random();
        // int blueBall = ran.nextInt(16) + 1;
        // ArrayList<Integer> redBalls = new ArrayList<>();
        // while (redBalls.size() < 6) {
        //     int rb = ran.nextInt(33) + 1;
        //     if (!redBalls.contains(rb))
        //         redBalls.add(rb);
        // }
        // Collections.sort(redBalls);
        // System.out.println("红球：" + redBalls + " 蓝球：[" + blueBall + "]");
    }
}
